package com.qxy.practice.concurrent;

/**
 * @author : 戚欣扬
 * @code :
 */
public class VolatileDemo1 {
    private static  boolean flag = false;

    public static void main(String[] args) {
        new Thread(() -> {
            while (!flag) {
                // do something
            }
            System.out.println("Thread terminated.");
        }).start();

        try {
            Thread.sleep(1000);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }

        flag = true; // 没有 volatile, 这个改变对其他线程不可见
    }

}


